import Fly from 'flyio/dist/npm/wx'
import baseUrlApi from './baseUrl'

const flyio = new Fly()

// http 请求拦截器
flyio.interceptors.request.use((req) => {
  wx.showNavigationBarLoading()
  req.baseURL = baseUrlApi
  console.log(req)
  //   req.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36' }
  console.log(req)
  return req
})

flyio.interceptors.response.use(
  (response, promise) => {
    console.log('response')
    wx.hideNavigationBarLoading()
    return promise.resolve(response.data)
  },
  (err, promise) => {
    wx.hideNavigationBarLoading()
    console.log(err.message)
    // wx.showToast({
    //   title: err.message,
    //   icon: 'none'
    // })
    return promise.resolve()
  }
)

export default flyio
